package com.bdqn.ch05.controller;

import com.bdqn.ch05.pojo.SysUser;
import com.bdqn.ch05.service.SysUserService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

@Controller
public class LoginController {
    @Resource
    private SysUserService userService;

    /**
     * 登录
     */
    @RequestMapping("/login")
    public String login(String usrName, String usrPassword, Model model, HttpSession session){
        SysUser sysUser = userService.login(usrName,usrPassword);
        if(sysUser == null){
            model.addAttribute("message","用户名或密码错误，登录失败");
            return "forward:/login.jsp";
        }
        session.setAttribute("loginUser",sysUser);
        return "main";
    }

    @RequestMapping("main")
    public String main(){

        return "main";
    }
}
